﻿using SharpDX.Toolkit.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bikiball.Graphic
{
    public class MapGraphicProperty : GraphicProperty
    {
        public SamplerState SamplerState { get; set; }

        public override void Draw(SharpDX.Matrix World, SharpDX.Matrix View, SharpDX.Matrix Proj, SharpDX.Toolkit.GameTime GameTime)
        {
            GraphicEngine.GraphicsDevice.SetVertexBuffer(0, this.VertexBuffer, this.VertexStride);
            GraphicEngine.GraphicsDevice.SetVertexInputLayout(this.InputLayout);
            GraphicEngine.GraphicsDevice.SetIndexBuffer(this.IndexBuffer, true);
            this.Effect.Parameters["View"].SetValue(View);
            this.Effect.Parameters["Projection"].SetValue(Proj);
            this.Effect.Parameters["World"].SetValue(World);
            this.Effect.Parameters["MySampler"].SetResource<SamplerState>(this.SamplerState);
            this.Effect.Parameters["Tex"].SetResource(this.Texture);
            this.Effect.Parameters["time"].SetValue(GameTime.TotalGameTime.Milliseconds / 1000.0f);

            foreach (EffectPass pass in this.Effect.Techniques[0].Passes)
            {
                pass.Apply();
                GraphicEngine.GraphicsDevice.DrawIndexed(PrimitiveType.TriangleList, this.NumIndices);
            }
        }
    }
}
